package com.tank.demo.chainOfResponsibility;

import com.tank.demo.abstractFactory.BaseBullet;
import com.tank.demo.abstractFactory.BaseGameObject;
import com.tank.demo.abstractFactory.BaseWall;
import com.tank.demo.facadeAndMediator.GameModel;
import com.tank.demo.utils.RectangleUtil;


public class BulletAndWallCollider implements Collider {
    @Override
    public boolean collide(BaseGameObject o1, BaseGameObject o2) {
        if (o1 instanceof BaseBullet && o2 instanceof BaseWall){
            if (RectangleUtil.intersects(o1,o2)){
                ((BaseBullet) o1).die();
                GameModel.getInstance().add(GameModel.gameAbstractFactory.createExplode(o1.x+o1.width/2,o1.y+o1.height/2));
            }
            return true;
        }else if (o1 instanceof BaseWall && o2 instanceof BaseBullet){
            collide(o2,o1);
        }
        return false;
    }
}
